package com.demo.tankGame05;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

/**
 * 绘制画框 放入 画板
 * @author gy
 * @date 2022/4/18
 */
public class YgyTankGame05 extends JFrame{

    private MyPanel mp = null;

    private static Scanner scanner = new Scanner(System.in);

    /**
     * 主启动类，将画框 启动起来
     * @param args
     */
    public static void main(String[] args) {
        YgyTankGame05 ygyTankGame05 = new YgyTankGame05();
    }


    public YgyTankGame05() {

        System.out.println("请输入选择 1: 新游戏 2: 继续上局");
        String key = scanner.next();

        this.mp = new MyPanel(key);
        // 启动 MyPanel线程，重新绘制面板
        Thread panelThread = new Thread(mp);
        panelThread.setName("画板");
        panelThread.start();

        this.add(mp);
        this.setSize(1300,1000);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.addKeyListener(mp);// 让JFrame 监听键盘事件
        this.setVisible(true);

        // 在 JFrame 中添加相应关闭窗口处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.keepRecord();
                System.exit(0);
            }
        });
    }
}
